<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>构造方法</title>
	</head>
	<body>
		<script type="text/javascript">
			//内置构造方法/函数
		var obj1=new Object();
		var str1=new String('123');
		//查看对象由哪个构造函数创建的
		console.log(obj1.constructor);
		console.log(str1.constructor);
		//若不用构造函数，定义2个具有相同属性的对象
		var o1={
			"name":"Lily",
			"age":14,
			sayHi.function(){console.log("hello")};
		}
		var o2={
			"name":"Tom",
			"age":15,
			sayHi.function(){console.log("hello")};
		}
		
		//2、自定义构造函数
		function Person(name,age){
			this.name=name;
			this.age=age;
			this.sayHi=function(){console.log("hello");};
		}
		var p1=new Person('zhangsan',20);
		var p2=new Person('lisi',24);
		console.log(p1.constructor);
		console.log(p1.constructor==p2.constructor);
		</script>
	</body>
</html>
